<template>
  <div class="container">
    <!-- 标题 -->
    <div class="settitle">
      <div class="setimg" @click="$router.back()">
        <img src="../assets/imgs/iconse/左箭头.png" alt="" />
      </div>
      <div class="text"><h2>设置</h2></div>
    </div>

    <!-- 账号设置栏 -->
    <router-link tag="div" to="/account" class="account">
      <div class="act">
        <span>账号设置</span>
        <p>绑定账号可快捷登录</p>
      </div>
      <div class="catimg">
        <img src="../assets/imgs/右箭头.png" alt="" />
      </div>
    </router-link>

    <!-- 打招呼设置栏 -->
    <router-link tag="div" to="/preins" class="account">
      <div class="act">
        <span>打招呼语</span>
        <p>与HR快速沟通</p>
      </div>
      <div class="catimg">
        <img src="../assets/imgs/右箭头.png" alt="" />
      </div>
    </router-link>

    <!-- 个性化推送设置栏 -->
    <div class="account">
      <div class="act">
        <span>个性化推送</span>
      </div>
      <van-switch
        v-model="checked"
        class="rit"
        active-color="#f78d73"
        inactive-color="#eee"
        size="20px"
        @click="delfun"
      />
    </div>
    <div class="setouts" @click="outin">
      <span>退出登录</span>
    </div>
  </div>
</template>

<script>

import { getCreatorJsonData } from "../api/creator.js";
import { getPreinsJsonData } from "../api/preins.js";
import { getChitchatJsonData } from "../api/chitchat.js";
export default {
  data() {
    return {
      checked: true,
    };
  },
  methods: {
    getPreinsFun() {
      getPreinsJsonData().then((data) => {
        localStorage.setItem("Preins", JSON.stringify(data["lists"]));
      });
    },
    getChitchatFun() {
      getChitchatJsonData().then((data) => {
        localStorage.setItem("Chitchat", JSON.stringify(data["chatlist"]));
      });
    },
    getCreatlistFun() {
      getCreatorJsonData().then((data) => {
        this.creator = data["creatorlist"];
        if (this.creator) {
          // 取出来用JSON.parse（）
          // 写入用JSON.stringify()
          let aa = JSON.stringify(this.creator);
          window.localStorage.setItem("keys", aa);
          // console.log("fristrun", aa);
        }
      });
      localStorage.setItem("collect", "[]");
    },
    outin() {
      // 清除所有存在localStorage中的数据
      localStorage.clear();
      this.$toast("登出成功");
      this.$router.push("/personal");

      // 推出后重新把数据存入localStorage
      this.getPreinsFun();
      this.getChitchatFun();
      this.getCreatlistFun();
    },
    delfun() {
      localStorage.setItem("checked", this.checked);
    },
  },
};
</script>

<style lang="scss" scoped>
.settitle {
  height: 60px;
  display: flex;
  align-items: center;
  background-color: #fff;
  box-shadow: 0px 0px 0px 1px rgba($color: #cccc, $alpha: 0.4);
  .setimg {
    height: 18px;
    position: absolute;
    left: 15px;
    img {
      height: 100%;
      display: block;
    }
  }
  .text {
    margin: 0 auto;
  }
}
.account {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: #fff;
  margin: 20px 0px;
  .act {
    font-size: 16px;
    box-sizing: border-box;
    padding-left: 15px;
    p {
      font-size: 12px;
      margin-top: 5px;
      color: #999;
    }
  }
  .catimg {
    height: 12px;
    margin-right: 30px;
    img {
      height: 12px;
    }
  }
  .rit {
    margin-right: 15px;
  }
}
.setouts {
  position: absolute;
  width: 80%;
  height: 45px;
  right: 0px;
  left: 0px;
  bottom: 20px;
  margin: auto;
  text-align: center;
  background-color: #eee;
  border-radius: 5px;
  span {
    font-size: 16px;
    font-weight: 600;
    line-height: 45px;
    color: #333;
  }
}
</style>